package com.ichoice.rabbitmq.rpc.helper.model;

import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;

/**
 * 消息延迟发送类
 *
 * @author xianrensawang
 * @date 2021/3/21
 */
public class DelayMessagePoster implements MessagePostProcessor {

    private final Long ttl;

    public DelayMessagePoster(Long ttl) {
        this.ttl = ttl;
    }

    @Override
    public Message postProcessMessage(Message message) throws AmqpException {
        message.getMessageProperties().setHeader("x-delay", ttl);
        return message;
    }
}
